fixed all compile errors and runtime exceptions