implements #1588
nicer error messages (untested)