Refactored XML generator per end user feedback + state requirements.