First version. Could be improved by avoiding suffix mismatch recomputation.