modified exercise 33 to a function