Fixed major bugs in text highlighting