Added debug config, better error handling