Switch to an event based approach instead of a callback one for middleware, per @DAddYE