added an optional parameter. It can be used to fix rounding errors
<= instead of < when comparing equal
finally fixed the subdivision bug