Merge "Add a bunch of unit tests for TF, and fix associated bugs."