fixed several memory leaks