XD-592

Builds upon Andy's work and fixes tests