diff --git a/lib/express/server.js b/lib/express/server.js
index <HASH>..<HASH> 100644
--- a/lib/express/server.js
+++ b/lib/express/server.js
@@ -231,11 +231,11 @@ Server.prototype.error = function(fn){
 
 Server.prototype.set = function(setting, val){
     if (val === undefined) {
-        var app = this;
-        do {
-          if (app.settings.hasOwnProperty(setting))
-            return app.settings[setting];
-        } while (app = app.parent);
+        if (this.settings.hasOwnProperty(setting)) {
+            return this.settings[setting];
+        } else if (this.parent) {
+            return this.parent.set(setting);
+        }
     } else {
         this.settings[setting] = val;
         return this;
Refactored app.set()