Fixed memory leaking (mostly).