Extract helpers, fix stuff, clean up xml builder