Removed unnecessary repeated multiplication by introducing variable lidx.