Improve error messages reported to the client.

This resolves #252.
Merge pull request #262 from zenhack/better-error-messages

Improve error messages reported to the client.