Cleaner middleware: static factory functions

A pattern to simplify parameterized middleware