refactor from code review question