Improved logic for parsing the xsd tree. Specifically addition of cycle-detection to prevent loops/stack-overflows.