pull out tag specific logic into tagutils

this pulls duplicate logic from run and register (including tests) into
anew module tagutils and new tests test_tagutils