Fix lots of warnings.

Incorporate changes from Andrey Mirtchovski.
9 files changed