Fix the last couple memory leaks, and do some code cleanup.