fix up and reorganise - get tests passing