Code for tutorial Part 2