Added debug code to detect leaks