Refactoring and code reorganization for better separation of concerns.