Refactoring to remove duplication in tests

Also some replanning.