refactoring from lesson 6