Improved error-handling and debugging info.