fix logic error, expand code & comments #2041

#2041 

It was just a greater than / less than reversal, but while I was in there I expanded it to make it easier to understand and debug.