Implemented some code cleanup and refactoring