refactor request into a function