Refactor txtopairs into smaller functions

Also adds a test for one of the new functions
Cool, I've fixed it