Code review and refactoring