Improves error handling, debug output