Modified Exercise 4.10 code, using case expression to combine
two functions into one.