problem with scoping the classes correctly when outputting the xml