Added debug logging to debug mode