     {
         restrict: 'A'
         require: 'ngModel'
-        scope:
-          true
+        scope: {
+        }
         link: (scope, elem, attrs, ngModelCtrl) ->
             options = getOptions scope, attrs
             isValid = makeIsValid options
             reformatRequired = false
+            scope.ctrlDownCount = 0
 
             ngModelCtrl.$parsers.unshift (viewVal) ->
                 noCommasVal = viewVal.replace /,/g, ''

            elem.on 'keydown', (event) ->
              keycode = event.which

              killEvent(event) unless isInertKey(keycode)

              return if invalidInput(elem, event)
              # unless isControlKey(keycode)
                # return if maxDigitsReached(event, 9) 
              
              initialPosition = elem[0].selectionStart 

              if keycode >= 48 and keycode <= 57 # insert number character
                unless maxDigitsReached(elem, 9)
                  newCursorPosition = findNewCharacterCursorPosition(elem, initialPosition)
                  insertCharacter(elem, event)
                  elem.val resetCommas(elem.val()) # reformat the number in place
                  elem[0].setSelectionRange(newCursorPosition, newCursorPosition) # set the new cursor position
                  triggerChange(elem)

              if keycode == 8 # backspace is pressed

                if elem[0].selectionEnd > elem[0].selectionStart # text is highlighted
                  # get the string before the selection and figure out how many commas it has
                  originalCursorPosition = elem[0].selectionStart
                  stringBeforeCursor = elem.val().slice(0, originalCursorPosition)
                  startingCommasBeforeCursor = (stringBeforeCursor.match(/,/g) || []).length

                  # delete the selected stuff and reset the commas
                  deleteSelectedRange(elem, event)
                  elem.val resetCommas(elem.val()) # reformat the number in place

                  # figure out how many commas were lost
                  finalStringBeforeCursor = elem.val().slice(0, originalCursorPosition)
                  endingCommasBeforeCursor = (finalStringBeforeCursor.match(/,/g) || []).length
                  commaDiff = startingCommasBeforeCursor - endingCommasBeforeCursor

                  # set the final cursor position
                  finalCursorPosition = originalCursorPosition - commaDiff
                  elem[0].setSelectionRange(finalCursorPosition, finalCursorPosition) # set the new cursor position

                  # trigger final change event
                  triggerChange(elem)

                else unless elem[0].selectionStart == 0 # do nothing if it's at the end of the end of the input
                  newCursorPosition = findNewBackspaceCursorPosition(elem, initialPosition)
                  backspacePressed(elem, event) # handle logic for backspace
                  elem.val resetCommas(elem.val()) # reformat the number in place
                  elem[0].setSelectionRange(newCursorPosition, newCursorPosition) # set the new cursor position

                  # trigger final change event
                  triggerChange(elem)
              
              if keycode == 46 # delete is pressed
                if elem[0].selectionEnd > elem[0].selectionStart # text is highlighted
                  # get the string before the selection and figure out how many commas it has
                  originalCursorPosition = elem[0].selectionStart
                  stringBeforeCursor = elem.val().slice(0, originalCursorPosition)
                  startingCommasBeforeCursor = (stringBeforeCursor.match(/,/g) || []).length

                  # delete the selected stuff and reset the commas
                  deleteSelectedRange(elem, event)
                  elem.val resetCommas(elem.val()) # reformat the number in place

                  # figure out how many commas were lost
                  finalStringBeforeCursor = elem.val().slice(0, originalCursorPosition)
                  endingCommasBeforeCursor = (finalStringBeforeCursor.match(/,/g) || []).length
                  commaDiff = startingCommasBeforeCursor - endingCommasBeforeCursor

                  # set the final cursor position
                  finalCursorPosition = originalCursorPosition - commaDiff
                  elem[0].setSelectionRange(finalCursorPosition, finalCursorPosition) # set the new cursor position

                  # trigger final change event
                  triggerChange(elem)

                else unless elem[0].selectionStart == elem.val().length
                  newCursorPosition = findNewDeleteCursorPosition(elem, initialPosition)
                  deletePressed(elem, event) # handle logic for backspace
                  elem.val resetCommas(elem.val()) # reformat the number in place
                  elem[0].setSelectionRange(newCursorPosition, newCursorPosition) # set the new cursor position

                  # trigger final change event
                  triggerChange(elem)
              
            elem.on 'keypress', (event) ->
              killEvent(event)

    inertKeys = [37, 39, 9, 33, 34]

    keyCodes = { 48:0, 49:1, 50:2, 51:3, 52:4, 53:5, 54:6, 55:7, 56:8, 57:9 }

    numberCharacterPressed = (keycode)->
      keycode >= 48 and keycode <= 57 # insert number character

    # Ctrl key helpers
    initCtrlKeys = (scope)->
      scope.ctrlDownCount = 0

    isCtrl = (event) ->
      event.which == 17

    ctrlDownCount = (scope)->
      scope.ctrlDownCount

    ctrlActive = (scope)->
      scope.ctrlDownCount > 0

    registerCtrl = (scope)->
      scope.ctrlDownCount += 1

    unregisterCtrl = (scope)->
      scope.ctrlDownCount -= 1

    # key recognition helpers
    isDelete = (event)->
      event.which == 46

    isBackspace = (event)->
      event.which == 8

    getOptions = (scope, attrs) ->
        options = angular.copy defaultOptions
