Error messages

Closes #863
Contains commits of #869
The constant is still named INVALID_DATA