fix crash when no ranges passed
fixed checking for ending mask
Don't waste space from ending mask for range