Fixed the memory leakage, it seems