Refactor tag generation