fix some issues with error handling, but not all of them (see #5)