solving memory leaks