Improved cleanup and checking on tag script