Refactoring and code cleanup.