complete refactor of tag handling