Some rework - still not quite correct. Still very slow.