   "Triggered whenever the input field loses focus.
   Re-validate what has been entered. Then update the model."
   [ev input-model min max callback previous-val]
-  (let [input-val (-> ev .-target .-value)
-        time-int (string->time-integer input-val)
-        validated-int (validated-time-integer time-int (deref-or-value min) (deref-or-value max) previous-val)]
+  (let [time-int (string->time-integer @input-model)
+        validated-int (validated-time-integer time-int @min @max previous-val)]
     (reset! input-model (display-string (time-int->hour-minute validated-int)))
     (when (and callback (not (= validated-int previous-val)))
       (callback validated-int))))
 
-(defn- updated-range-time
-  "One of the values of a range has changed. Update the min or max of the other input.
-  Return true if the value has been accepted."
-  [model max-or-min-model]
-  (let [new-time-int (string->time-integer @model)]
-    (reset! max-or-min-model new-time-int)))
-
 (defn- updated-range-from-time
-  "The From of a range has changed. Update the min of the other input.
-  Send the new value to the caller using the callback."
-  [model max-or-min-model previous-vals callback]
-  (updated-range-time model max-or-min-model)
-  (when callback
-    (let [new-vals [@max-or-min-model (last previous-vals )]]
-      (callback new-vals))))
+  "The From of a range has changed. If necessary, update the model of the other input.
+  Send the new values to the caller using the callback."
+  [from-model to-model previous-vals callback]
+  (let [from-int (string->time-integer @from-model)
+        to-int   (string->time-integer @to-model)]
+    (if (> from-int to-int)
+      (reset! to-model @from-model))
+    (when callback
+      (let [new-vals [(string->time-integer @from-model)(last previous-vals)]]
+        (callback new-vals)))))
 
 (defn- updated-range-to-time
-  "The To of a range has changed. Update the max of the other input.
-  Send the new value to the caller using the callback."
-  [model max-or-min-model previous-vals callback]
-  (updated-range-time model max-or-min-model)
-  (when callback
-    (let [new-vals [(first previous-vals) @max-or-min-model]]
-      (callback new-vals))))
+  "The To of a range has changed. If necessary, update the model of the other input.
+  Send the new values to the caller using the callback."
+  [from-model to-model previous-vals callback]
+  (let [from-int (string->time-integer @from-model)
+        to-int   (string->time-integer @to-model)]
+    (if (< to-int from-int )
+      (reset! from-model @to-model))
+    (when callback
+      (let [new-vals [(first previous-vals)(string->time-integer @to-model)]]
+        (callback new-vals)))))
 
 (defn- atom-on
   [model default]

    (if-not (valid-time-integer? deref-model @min @max)
      (throw (js/Error. (str "model " deref-model " is not a valid time integer or is outside the min/max range."))))
     (fn [& {:keys [model disabled hide-border show-time-icon style]}]
       [private-time-input input-model (deref-or-value model) min max
         :on-change on-change
         :disabled disabled
         :hide-border hide-border

        :align :center
        :children [(when from-label [label :label from-label])
                   [private-time-input
                      :model input-from-model
                      :previous-val (first (deref-or-value model))
                      :min min
                      :max max
                      :on-change #(updated-range-from-time input-from-model input-to-model (deref-or-value model) on-change)
                      :disabled disabled
                      :hide-border hide-border
                      :show-time-icon show-time-icon
                      :style style]
                   (when to-label [label :label to-label])
                   [private-time-input
                      :model input-to-model
                      :previous-val (last (deref-or-value model))
                      :min min
                      :max max
                      :on-change #(updated-range-to-time input-from-model input-to-model (deref-or-value model) on-change)
                      :disabled disabled
                      :hide-border hide-border
                      :show-time-icon show-time-icon
                      :style style]]])))
