separate method of building xml
refactor 'write' method
lessen code metrics complexity