refactoring, commenting, general code cleanup