Added proper debug logging