formatted code and fixed compile error