code review and refactoring