changed the order of middleware