code review and refactor