it seems like so much extra code to pre-define these functions. Why not pass them in as inline, anonymous functions like before? Besides less boilerplate code, I think that would make the logic more readable.