fixing compile errors and cleaning code