LIB001-721: Tidying up code to produce XML output on errors