refactored highlighting code