Add more error reporting and debug logging