Simplify logic, pretty-print xml