Code for Part 3 of the tutorial