moved code for HTTP request handling to separate functions