further improved error handling