fix handling of end of match