refactor request handling