Better at handling flaky connection
XPlanner errors now raise exceptions
code tidy