Got rid of a couple of memory leaks and smoothed stuff out a bit.