improved tagging script