Added user agent and Accept header, and added exiting on errors.