code clean up and pass req in context