refactor tsv module to remove some duplication