Fixed memory leaks and removed TTask dependence