Code clean up and less memory leakage in engine.