The third condition looks wierd but 4 tests are failing without it. Not sure whether it should be fixed some other way.