Mark last tag as final, handles case of missing end tag