refactored some of http client code