Refactor XML reading