Revised exercise 3

Based on reviewer feedback, the code in exercise 3 was revised to be
semantically correct.