Fixing memory leaks & a few crashes