modified tag parser to be more robust