Fix finding longest substring