Better error handling and debug options