Pulled tps calculation outside of for loop