bug fixes and more error reporting