refactoring & finalization for handin