fixed the memory leaks, improved debugging caps