Refactor to improve code quality