fixing NL implementation, many indices were being summed in the wrong loop