Refactor and XML manipulation