refactor requests code