made error handling and debug info consistent