Added James' code for Part 2 (before refactoring)