Updated code for Part 2