Bug fix where XML elements were being lost