Exercise: Refactor previous solutions to use functions