Fixed bugs and compile errors