bug fixes and proper error messages