Fix error in constraining to range