Fixed a few compiler warnings and minor bugs