move req handling to a function