Add debugging to memory checking