refactoring after a code review from a friend