reworked the LCS sum loop to fix sum values of NaN