bugfixes and improved error reporting