Fixed errors when running the .tng function and cleaning up