added meaningful error messages
added tests