bugfixes to error handling