Finished code for Part 1