changed the handler so that custom middleware is called after all the standard middleware