fixes selection issue when rapidly clicking the expand/collapse all tabs button
fixed an issue with note highlighting and slightly refactored for clarity/performance