Refactor tag validation.