fixed up memory leaks in engine