Made the XML parser cope with some errors that it missed before. Also found a couple of performance optimisations for it.