diff --git a/lib/handlebars.js b/lib/handlebars.js
index <HASH>..<HASH> 100644
--- a/lib/handlebars.js
+++ b/lib/handlebars.js
@@ -191,6 +191,16 @@ var Handlebars = {
     }
 
     return out;
+  },
+
+  handleInvertedSection: function(lookup, context, fn) {
+    var out = "";
+    if(Handlebars.isFunction(lookup) && Handlebars.isEmpty(lookup())) {
+      out = out + fn(context);
+    } else if (Handlebars.isEmpty(lookup)) {
+      out = out + fn(context);
+    }
+    return out;
   }
 }
 
@@ -308,8 +318,7 @@ Handlebars.Compiler.prototype = {
     var fnId = "fn" + this.pointer.toString();
     this.fn += "var " + fnId + " = function(context) {" + result + "}; ";
     this.fn += "lookup = " + this.lookupFor(mustache) + "; ";
-    this.fn += "if(Handlebars.isFunction(lookup) && Handlebars.isEmpty(lookup())) out = out + " + fnId + "(context);";
-    this.fn += "else if (Handlebars.isEmpty(lookup)) out = out + " + fnId + "(context);";
+    this.fn += "out = out + Handlebars.handleInvertedSection(lookup, context, " + fnId + ");"
 
     this.openBlock = false;
     this.inverted = false;
Got handleInvertedSection written up.