Error messages

Closes #863
Contains commits of #869