Refactored and added functions calculate_tmvDB and calculate_tmvT.