a lot of compiler warning fixes

I've fixed all compiler warnings and one bug.
explicitly type conversions