Added better error checking for responses from server.