Tidy up middleware