Put writing in separate class and use proper xml writer