added meaningful error messages
added tests to prove 78bbe4c and 2db9a86