refactor web request handler