Bug/invalid restresponse cast

This one goes on top of the rake pull request.

Fixes #447 and #431.