first solution for problem 2. time to refactor