Better xml handling

Takes away some of the complexity involved with xml handling. Should be easier to maintain now - and also work better.