Refactor request code