Make conversion from XML more robust, fix bug in test.