Reworking algorithm lcs