Refactor and simplify tags mechanism