move middleware to end