Fix Compiler Warnings and some minor bugs