Added error checking around handling responses.