refactored xml reading and started xml writing