Further progress on rewrite - sort of works