Most tests now passing. One tricky issue left to sort out.