big rewrite
improve xml handling