unify before and after with the use of middleware