                 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 }

        attributedText = expandedText
    }
    
    fileprivate func textWithLinkReplacement(_ line : CTLine, text : NSAttributedString, linkName : NSAttributedString) -> NSAttributedString {
        let lineText = text.textForLine(line)
        var lineTextWithLink = lineText
        (lineText.string as NSString).enumerateSubstrings(in: NSMakeRange(0, lineText.length), options: [.byWords, .reverse]) { (word, subRange, enclosingRange, stop) -> () in
            let lineTextWithLastWordRemoved = lineText.attributedSubstring(from: NSMakeRange(0, subRange.location))

        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, text: text, linkName: link)
            let collapsedLines = NSMutableAttributedString()
            let differenceFromStart = (collapsedNumberOfLines-1) - lineIndex.index
            let emptyLineIndent = (2 + differenceFromStart)
            if collapsedNumberOfLines-emptyLineIndent > 0 {
                for index in 0...collapsedNumberOfLines-emptyLineIndent  {
                    collapsedLines.append(text.textForLine(lines[index]))
                }
