refactored XML writing code in correction