fixed all the memory leaks