added meaningful error messages
added tests to prove ff6a26f and bba1ebb