solve memory leaks