fix mismatched ends