finish fixing memory leaks