encapsulated the request function, so that failures can be handled more effectively