exercise 13 refactored