Refactor and tweak tagging feature