Cleanup link_states and fix a rare highlight bug