Refactoring the tag script