Fixed an issue with error response parsing. GitHub #151.

Also cleaned up some of the code to handle URI formation.