Fix bug in code

Also add source of tutorial that Max (me) is using to implement all of
this.