Fixed match error on tags and improved efficiency