fix some memory leaks (I think)