Moved XML freeing to a more sensible place