Implemented the tstats command.

Very complicated but all tests pass.