Bugs fixed. Fixed memory leaks (hopefully).