Finished code for part1