fixed an issue with note highlighting and slightly refactored for clarity/performance