Improved some error messages.

Also did some minor code cleanup.
Merge branch 'baagaard/fix-error-messages'

* baagaard/fix-error-messages:
  Improved some error messages.