improved highlighting logic