Minor code cleanup

A follow-up to our discussion on Twitter.
It's not complete, but shows several points for code improvements.

You may disagree on some aspects, so feel free to discard them or ask for details :)
Generally, if you pattern match on the last argument, you can omit it from the function definition and use `function` keyword followed by a pattern matching expression.