Fixing some of the more obvious memory leaks