     d = content.substring(0, index_start) + data + content.substring(index_start + length)
     return d
 
-  nullTimeField = (content, field) ->
-    replace_string = ""
-    #TODO: validate this
-    for i in [0..time_spec["#{field}_l"]]
-      replace_string += "0"
-
-    return setTimeField(content, field, replace_string)
-
   processButton = (content) ->
     current_content = duration_elem.data("content")
-    if content.substring(0, 6) == "clear-"
-      # backspace
-      clear_field = content.substring(6)
-      current_content = nullTimeField(current_content, clear_field)
-    else
-      data = parseInt(content.substring(0, content.length - 1))
-      field = content.substring(content.length - 1)
-      field_data = parseInt(getTimeField(current_content, field))
-      field_data += data
-      if field_data < 0
-        hours_field = parseInt(getTimeField(current_content, "h"))
-        minutes_field = parseInt(getTimeField(current_content, "m"))
-        if field == "s"
-          if minutes_field == 0 and hours_field > 0
-            # Take 1h to minutes field.
-            hours_field -= 1
-            current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
-            minutes_field += 60
+    data = parseInt(content.substring(0, content.length - 1))
+    field = content.substring(content.length - 1)
+    field_data = parseInt(getTimeField(current_content, field))
+    field_data += data
+    if field_data < 0
+      hours_field = parseInt(getTimeField(current_content, "h"))
+      minutes_field = parseInt(getTimeField(current_content, "m"))
+      if field == "s"
+        if minutes_field == 0 and hours_field > 0
+          # Take 1h to minutes field.
+          hours_field -= 1
+          current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
+          minutes_field += 60
 
-          if minutes_field > 0
-            # Take 1 minute to seconds field.
-            minutes_field -= 1
-            field_data += 60
-            current_content = setTimeField(current_content, "m", zeroPad(minutes_field, time_spec.m_l))
-          else
-            field_data = 0
-
-        else if field == "m"
-          if hours_field > 0
-            # Take 1 hour to minutes field.
-            hours_field -= 1
-            field_data += 60
-            current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
-          else
-            field_data = 0
+        if minutes_field > 0
+          # Take 1 minute to seconds field.
+          minutes_field -= 1
+          field_data += 60
+          current_content = setTimeField(current_content, "m", zeroPad(minutes_field, time_spec.m_l))
         else
           field_data = 0
 
-      if (field == "s" or field == "m") and field_data >= 60
-        if field == "s"
-          minutes_field = parseInt(getTimeField(current_content, "m"))
-          minutes_field += 1
-          field_data -= 60
-          if minutes_field >= 60
-            minutes_field -= 60
-            hours_field = parseInt(getTimeField(current_content, "h"))
-            hours_field += 1
-            current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
+      else if field == "m"
+        if hours_field > 0
+          # Take 1 hour to minutes field.
+          hours_field -= 1
+          field_data += 60
+          current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
+        else
+          field_data = 0
+      else
+        field_data = 0
 
-          current_content = setTimeField(current_content, "m", zeroPad(minutes_field, time_spec.m_l))
-
-        if field == "m"
-          field_data -= 60
-          hours_field = parseInt getTimeField(current_content, "h")
+    if (field == "s" or field == "m") and field_data >= 60
+      if field == "s"
+        minutes_field = parseInt(getTimeField(current_content, "m"))
+        minutes_field += 1
+        field_data -= 60
+        if minutes_field >= 60
+          minutes_field -= 60
+          hours_field = parseInt(getTimeField(current_content, "h"))
           hours_field += 1
           current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
 
-      field_data = zeroPad field_data, time_spec[field + "_l"]
-      current_content = setTimeField current_content, field, field_data
+        current_content = setTimeField(current_content, "m", zeroPad(minutes_field, time_spec.m_l))
+
+      if field == "m"
+        field_data -= 60
+        hours_field = parseInt getTimeField(current_content, "h")
+        hours_field += 1
+        current_content = setTimeField(current_content, "h", zeroPad(hours_field, time_spec.h_l))
+
+    field_data = zeroPad field_data, time_spec[field + "_l"]
+    current_content = setTimeField current_content, field, field_data
 
     duration_elem.data "content", current_content
     c = current_content


  modal_elem.find(".add-timer-button").on "click", ->
    content_switch.userActivity()
    content = jq(this).data("content").trim()
    processButton content

  jq(".add-custom-timer-plus").on "click", ->

    c = duration_elem.data("content")
    seconds = parseInt(c.substr(0, 3)) * 3600 + parseInt(c.substr(3, 2)) * 60 + parseInt(c.substr(5, 2))
    if seconds == 0
      # If no time is set, try getting duration for fixed-length items
      seconds = jq(this).data("duration")

    if seconds?
      jq.post "/homecontroller/timer/create",
        name: name
        duration: seconds

    modal_elem.find(".close").click()

