         let doCols = (mode != .Rows)
         
         guard var (i0, j0) = next() else {
-            return false
+            if mode == .Both { // The area left is O. Exit iteration.
+                return false
+            } else {           // The target row/col is O. Continue iteration.
+                return true
+            }
         }
         
         if doRows && i0 > itr {

        return true
    }
    
    override func postProcess() {
        switch mode {
        case .Rows:
            var step = 0
            align: while step < rows {
                for j in 0 ..< cols {
                    let arr = (step ..< rows).filter{ result[$0, j] != 0}
                    if arr.count == 1, let i = arr.first {
                        apply(.SwapRows(i, step))
                        step += 1
                        continue align
                    }
                }
                step += 1
            }
        case .Cols:
            var step = 0
            align: while step < cols {
                for i in 0 ..< rows {
                    let arr = (step ..< cols).filter{ result[i, $0] != 0}
                    if arr.count == 1, let j = arr.first {
                        apply(.SwapCols(j, step))
                        step += 1
                        continue align
                    }
                }
                step += 1
            }
        default: ()
        }
    }
    

        
        defer {
            switch p.mode {
            case .Both:
                if current.0 + 1 >= p.rows {
                    current = (p.itr, current.1 + 1)
                } else {
                    current = (current.0 + 1, current.1)
                }
            case .Rows:
                current = (current.0 + 1, current.1)
            case .Cols:
                current = (current.0, current.1 + 1)
            }
        }
        
