                 }
                 i += run.length
             }
-
+            
             fatalError("Couldn't find target run")
         }
-
+        
         private func runPriorToOffset(offset: Int) -> Run? {
             if (offset == 0) {
                 return nil
             }
-
+            
             for i in (0 ... offset - 1).reverse() {
                 let run = runAtOffset(i)
                 if (run != nil) {
                     return run
                 }
             }
-
+            
             return nil
         }
-
+        
         private func runAtOffset(offset: Int) -> Run? {
             var i = offset
             var firstRun = true

                    run = potentialLine.runAtOffset(i)!
                    offsetToShift = i + 1 - potentialLine.runOffset(run)
                }

                if (!potentialLine.shiftRun(run, offset: offsetToShift)) {
                    return false
                }
            }
        }

        return true
    }

    private struct PackedLine {
        private var runs: [Run] = []
        private let lineLength: Int
        private let totalLineSlop: Int

        private class Run {
            var extraLeadingSpace: Int
            let index: Int
            let length: Int

            init(extraLeadingSpace: Int, index: Int, length: Int) {
                self.extraLeadingSpace = extraLeadingSpace
                self.index = index
                self.length = length
            }
        }


        init(rules: [Int], lineLength: Int) {
            self.lineLength = lineLength
            var i = 0

            let isLastRun = run.index == runs.count - 1
            let nextRun: Run? = isLastRun ? nil : runs[run.index + 1]
            let slopAvailableForShift = isLastRun
                ? self.trailingSpaceOnLine()
                : nextRun!.extraLeadingSpace
            
            let shortfall = offset - slopAvailableForShift
            if (shortfall > 0) {
                // TODO: offset should become atLeastOffset
                shiftRun(runs[run.index + 1], offset: shortfall)
            }
            
            run.extraLeadingSpace += offset
            if (!isLastRun) {
                nextRun!.extraLeadingSpace -= offset
                // TODO Assert the next run had the space to give
            }
            
            return shortfall <= 0
        }
    }
}
