Pseudo code for Part 2