improved error handling and logging; see issue #266