Improved error-handling