Refactoring and cleanup.