Trying to put phased middleware near end to avoid errors in production