diff --git a/core/misc/states.js b/core/misc/states.js
index 2656807..2309eb1 100644
--- a/core/misc/states.js
+++ b/core/misc/states.js
@@ -20,12 +20,16 @@ Drupal.behaviors.states = {
   attach: function (context, settings) {
     var $context = $(context);
     for (var selector in settings.states) {
-      for (var state in settings.states[selector]) {
-        new states.Dependent({
-          element: $context.find(selector),
-          state: states.State.sanitize(state),
-          constraints: settings.states[selector][state]
-        });
+      if (settings.states.hasOwnProperty(selector)) {
+        for (var state in settings.states[selector]) {
+          if (settings.states[selector].hasOwnProperty(state)) {
+            new states.Dependent({
+              element: $context.find(selector),
+              state: states.State.sanitize(state),
+              constraints: settings.states[selector][state]
+            });
+          }
+        }
       }
     }
 
@@ -52,7 +56,9 @@ states.Dependent = function (args) {
 
   this.dependees = this.getDependees();
   for (var selector in this.dependees) {
-    this.initializeDependee(selector, this.dependees[selector]);
+    if (this.dependees.hasOwnProperty(selector)) {
+      this.initializeDependee(selector, this.dependees[selector]);
+    }
   }
 };
 
@@ -89,7 +95,11 @@ states.Dependent.prototype = {
    *   dependee's compliance status.
    */
   initializeDependee: function (selector, dependeeStates) {
-    var state;
+    var state, self = this;
+
+    function stateEventHandler(e) {
+      self.update(e.data.selector, e.data.state, e.value);
+    }
 
     // Cache for the states of this dependee.
     this.values[selector] = {};
@@ -108,9 +118,7 @@ states.Dependent.prototype = {
         this.values[selector][state.name] = null;
 
         // Monitor state changes of the specified state for this dependee.
-        $(selector).bind('state:' + state, {selector: selector, state: state}, $.proxy(function (e) {
-          this.update(e.data.selector, e.data.state, e.value);
-        }, this));
+        $(selector).bind('state:' + state, {selector: selector, state: state}, stateEventHandler);
 
         // Make sure the event we just bound ourselves to is actually fired.
         new states.Trigger({ selector: selector, state: state });
@@ -547,8 +555,8 @@ function ternary (a, b) {
 }
 
 // Inverts a (if it's not undefined) when invert is true.
-function invert (a, invert) {
-  return (invert && typeof a !== 'undefined') ? !a : a;
+function invert (a, invertA) {
+  return (invertA && typeof a !== 'undefined') ? !a : a;
 }
 
 // Compares two values while ignoring undefined values.
