cleaning up middleware stuff