Cleaned highlight detection code and made it work for rotated text as well.