Fixed a memory leak among other things.