improved error messages, added a test case