refactor http request logic