slightly improve internal error handling