Fixed leaks and other memory wizardry.
Now it is working, apparently.