Clean up and make code easier to test by moving TF calculations to static methods