Debug ifdefs and mem leak fix