Fix range overflow check with more universal approach for IE9 fix