plug a bunch of potential memory leaks