From line 2 to line 3,

The reason the negative N/S is not included anymore could be that N is geater than S.

If N > S, then N/S is greater than 1.0. Then (1 -N/S) is negative.

There are no logarithms for negative quantities.

From line 3 to line 4,

The reappearance of the +,- outside of the logarithm is due to the +,- of the sigma_m in line 3.

In line 4, the sigma_m is only positive.