solution to problem 2
dry refactoring