Smarter algorithm for clef changes