Code for part 1 - part 3 of the tutorial