Add docstrings and update tag parser logic to preserve order