factor out request processing