fixes memory leaks