Refactoring to improve code quality