Part 2 of Lecture 6's code