more tweaks and bugfixes on error handling