more debugging fixes
refactor xml read/write routines