     // TODO: investigate why replacement fails
     return out + "]"
   }
-}
+
+}
+  // utility functions in CGDisplayMode filtering
+  struct Sieve {
+    let propertyList = ["frequency", "kCGDisplayHorizontalResolution", "DepthFormat", "BitsPerSample"]
+    var largest:[String:Int]
+    var filtered:[String:[Int]]
+    
+    init() {
+      largest = [String:Int]()
+      filtered = [String:[Int]]()
+      for prop in propertyList {
+        largest[prop] = 0
+        filtered[prop] = []
+      }
+    }
+
+    // invoking maxValue update & record-keeping
+    mutating func findMaxValueAndIndices(in modesObject:[CGDisplayModeFromJSON], withIndexArray arr:[Int]) {
+      for prop in propertyList {
+        arr.forEach { i in
+          switch modesObject[i][prop] {
+          // update for new maxValue   
+          case let x where x > largest[prop]!:
+            largest[prop] = x
+            filtered[prop] = [i]
+          // add record of elements for current maxValue 
+          case let x where x == largest[prop]!:
+            filtered[prop]!.append(i)
+          default: break
+          }
+          if filtered[prop]!.count == arr.count {
+            filtered[prop] = [arr[0]]
+          }
+        }
+      }
+    }
+
+    private func look(for element:Int) -> Bool {
+      return filtered["DepthFormat"]!.contains(element) && filtered["BitsPerSample"]!.contains(element)
+    }
+
+    // find the best mode for certain (but not all) condition
+    // similar to Arrow's law, we DO NOT guarantee the mode is uniformly the best
+    // but we do try to winnow out the bad modes ;)
+    subscript(index:String) -> [Int] {
+      get {
+        switch index {
+        case "bestModeByRefreshRate": return filtered["frequency"]!.filter { look(for: $0) }
+        case "bestModeByResolution": return filtered["kCGDisplayHorizontalResolution"]!.filter { look(for: $0) }
+        case "bestMode": return Array(Set(self["bestModeByResolution"]).intersection(self["bestModeByRefreshRate"]))
+        default: return [0]
+        }
+      }
+    }
+  }
 
 // return width, height and frequency info for corresponding displayID
 // TODO: eliminate the use of DisplayInfo in favor of the newer, and more informative CGDisplayModeFromJSON
-struct DisplayInfo:Hashable & Comparable & Equatable {
-  static let MAX_SCALE = 10
+struct DisplayInfo: Comparable & Equatable {
   var width, height, scale, frequency, resolution:Int
   var bps, depth:Int
   var modeID:Int32

  var kCGDisplayPixelsWide = 3840;
  var kCGDisplayResolution = 1;
  var kCGDisplayVerticalResolution = 163;
}
// use the object as key in a later process of mode filtering/winnowing
extension CGDisplayModeFromJSON: Hashable & Equatable {
  func hash(into hasher: inout Hasher) {
    hasher.combine(Width)
    hasher.combine(Height)
    hasher.combine(kCGDisplayPixelsWide)
    hasher.combine(kCGDisplayPixelsHigh)
  }
  static func == (lhs: Self, rhs: Self) -> Bool {
    return lhs.Width == rhs.Width && lhs.kCGDisplayPixelsWide == rhs.kCGDisplayPixelsWide &&
          lhs.Height == rhs.Height && lhs.kCGDisplayPixelsHigh == rhs.kCGDisplayPixelsHigh
  }

  // for property loop in mode filtering


    if args.count == 2 { return }

    if args[2] > DisplayUserSetting.MAX_SCALE {
      height = args[2]
      if args.count > 3 { scale = args[3] }
    }
