James’ code for part one.