     }
   }
 
-// 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: Comparable & Equatable {
-  var width, height, scale, frequency, resolution:Int
-  var bps, depth:Int
-  var modeID:Int32
-  var mode:CGDisplayMode
-  //var colorDepth, resolution:Int
-
-  init(displayID:CGDirectDisplayID, modeFromJSON:CGDisplayModeFromJSON, mode:CGDisplayMode) {
-    width = modeFromJSON.Width
-    height = modeFromJSON.Height
-    resolution = modeFromJSON.kCGDisplayHorizontalResolution
-    modeID = Int32(modeFromJSON.IODisplayModeID)!
-    depth = modeFromJSON.DepthFormat
-    bps = modeFromJSON.BitsPerSample
-    
+struct MyDisplayMode {
+  let mode:CGDisplayMode
+  let modeFromJSON:CGDisplayModeFromJSON
+  init(mode:CGDisplayMode, modeFromJSON:CGDisplayModeFromJSON) {
     self.mode = mode
-    scale = modeFromJSON["scale"]        
-    frequency = modeFromJSON["frequency"]
-  }
-  // TODO: get rid of it,since we are not comparing DisplayInfo
-  static func < (lhs: Self, rhs: Self) -> Bool {
-    return lhs.scale != rhs.scale ? lhs.scale < rhs.scale : lhs.width < rhs.width
-  }
-
-  static func == (lhs: Self, rhs: DisplayUserSetting) -> Bool {
-    var bool = rhs.width == lhs.width
-
-    if rhs.height != nil { bool = bool && rhs.height == lhs.height }
-    if rhs.scale != nil { bool = bool && rhs.scale == lhs.scale }
-    return bool
-  }
-
+    self.modeFromJSON = modeFromJSON
+  }
 }
 
 
 // DisplayMode & DisplayID management center
 class DisplayManager {
   let displayID:CGDirectDisplayID,
-      displayInfo:[DisplayInfo],
+      displayInfo:[MyDisplayMode],
       modeID:Int32,
       mode: CGDisplayMode
 

  func set(with setting: DisplayUserSetting) {
    print("setting", setting)
    // comparing DisplayUserSetting with DisplayInfo
    guard let di = displayInfo.last(where: { setting == $0 }) else{
      print("This mode is unavailable")
      return
    }

    
    let modeIndex = modes.firstIndex(of: mode)!
     
    guard var modesFromJSON = CGDisplayModeFromJSON.decode(from: modes) else {
      self.displayInfo = []
      return
    }

    for i in 0..<modesFromJSON.count {
      modesFromJSON[i].frequency = modesFromJSON[i].getRefreshRate(by:displayID)
    }
   

    // group modes by `scale, width, height` and then carefully winnow out improper modes in each group            
    let category = Array(0..<modesFromJSON.count).reduce(into:[:]) { (category: inout [CGDisplayModeFromJSON:[Int]], i) in
      category[modesFromJSON[i], default: []].append(i)
    }
    
    let cursor = modesFromJSON[modeIndex]
    
    var shortlist = [CGDisplayModeFromJSON:[Int]]()
    // key is only used to identify current mode setting
    for (key, arr) in category {
      var sieve = Sieve.init()

      sieve.findMaxValueAndIndices(in: modesFromJSON, withIndexArray: arr)

      var bestMode = sieve["bestMode"]
      if key == cursor {
        if bestMode.allSatisfy({ modesFromJSON[modeIndex] ~= modesFromJSON[$0] }) {
          bestMode = [modeIndex]
        } else if !bestMode.contains(modeIndex) {
          bestMode.append(modeIndex)
