                 let lineTextWithLastWordRemovedRect = lineTextWithLastWordRemoved.boundingRectForWidth(self.frame.size.width)
                 let wordRect = linkName.boundingRectForWidth(self.frame.size.width)
                 let width = lineTextWithLastWordRemoved.string == "" ? self.frame.width : wordRect.size.width
-                self.linkRect = CGRect(x: lineTextWithLastWordRemovedRect.size.width, y: self.font.lineHeight * CGFloat(self.collapsedNumberOfLines-1), width: width, height: wordRect.size.height)
+                self.linkRect = CGRect(x: lineTextWithLastWordRemovedRect.size.width, y: self.font.lineHeight * CGFloat(lineIndex.index), width: width, height: wordRect.size.height)
                 stop.pointee = true
             }
         }
         return lineTextWithLink
     }
-    
     
     fileprivate func getCollapsedTextForText(_ text : NSAttributedString?, link: NSAttributedString) -> NSAttributedString? {
         guard let text = text else { return nil }

        if (collapsedNumberOfLines > 0 && collapsedNumberOfLines < lines.count) {
            let lastLineRef = lines[collapsedNumberOfLines-1] as CTLine
            let lineIndex = findLineWithWords(lastLine: lastLineRef, text: text, lines: lines)
            let modifiedLastLineText = textWithLinkReplacement(lineIndex.line, text: text, linkName: link)
            let collapsedLines = NSMutableAttributedString()
            let emptyLineIndent = lineIndex.index == collapsedNumberOfLines-1 ? lineIndex.index : lineIndex.index + 2
            if (collapsedNumberOfLines - emptyLineIndent > 0) {
                for index in 0...collapsedNumberOfLines-emptyLineIndent  {
                    collapsedLines.append(text.textForLine(lines[index]))
                }

        }
        return text
    }


fileprivate func findLineWithWords(lastLine: CTLine, text: NSAttributedString, lines: [CTLine]) -> LineIndexTuple {
    var lastLineRef = lastLine
    var lastLineIndex = collapsedNumberOfLines - 1
    var lineWords = spiltInToWords(str: text.textForLine(lastLineRef).string as NSString)
    while lineWords.count < 2 && lastLineIndex > 0 {
        lastLineIndex -=  1
        lastLineRef = lines[lastLineIndex] as CTLine
        lineWords = spiltInToWords(str: text.textForLine(lastLineRef).string as NSString)
    }
    return (lastLineRef, lastLineIndex)
}

fileprivate func spiltInToWords(str: NSString) -> [String] {
    var strings: [String] = []
    str.enumerateSubstrings(in: NSMakeRange(0, str.length), options: [.byWords, .reverse]) { (word, subRange, enclosingRange, stop) -> () in
        if let unwrappedWord = word {
            strings.append(unwrappedWord)
        }
        if strings.count > 1 { stop.pointee = true }
    }
    return strings
}

    fileprivate func textFitsWidth(_ text : NSAttributedString) -> Bool {
        return (text.boundingRectForWidth(frame.size.width).size.height <= font.lineHeight) as Bool
    }
