Refactored xml parsing