refactor adjacent tag merging