Code accomanying part 6 of blog series