             // Sweep through all frames from top to bottom
             for point in endPoints {
                 if point.isStart {
+                    let newFrame = point.frame
                     // If collisions, resize and reposition the frames.
                     if !sweepState.isEmpty {
                         if !areCollisions { areCollisions = true }

        })

        for value in domain {
            if Date.timeIntervalSinceReferenceDate-startTime > 0.95 {
                return .timeout
            }
            if cancelled {

                        }
                        point.frame.width = newWidth
                    }
                    if activeGroup.isEmpty {
                        activeGroup.append([point.frame])
                        for frame in sweepState {
                            activeGroup.append([frame])
                        }
                    }
                    else {
                        // Stores index of column to be added to
                        var addToIndex: Int?
                        // Counter keeps index of columns
                        var cIndex = 0
                        // Iterate through all columns in group
                        for column in activeGroup {
                            // Stores if this column is valid for the new frame
                            var validColumn = true
                            // If a frame in column is currently in the sweep state then the newframe might collide with it.
                            // So this column is not valid.
                            for frame in column where sweepState.contains(frame) {
                                validColumn = false
                            }
                            // If this column is valid store the addToIndex
                            if validColumn {
                                addToIndex = cIndex
                            }
                            // Increment counter
                            cIndex += 1
                        }
                        // If an index was found, add frame to column in that index
                        if let index1 = addToIndex {
                            var col = activeGroup[index1]
                            col.append(newFrame)
                            activeGroup[index1] = col
                        }
                            // If no index was found append a new column
                        else {
                            activeGroup.append([newFrame])
                        }
                    }
                    sweepState.insert(newFrame)
                }
                else {
                    // Remove from sweepingline and add to eventFrames
                    let frame = point.frame
                    sweepState.remove(frame)
                    // If sweepstate is now empty then the current active group is finished, append it to collisonGroups and reset active group.
                    if sweepState.isEmpty {
                        collisionGroups.append(activeGroup)
                        activeGroup.removeAll()
                    }
                    eventFrames.append(frame)
                    domains.append(self.domain(forFrame: frame, .subOptimal))
                    frameIndices[frame] = index
