Debugging

A bunch of debugging on this. I mostly had some dumb off by one errors
on the version I wrote (the first one) and some small logic stuff, and
the rest of the errors were all misuse of lambda expressions where I
should use def statements, and such.