The program does not currently consider minor keys. Adding this to the mix would immediately leave any key determination be ambiguous as the major and its relative minor share the same pitches. Also there are complications arising from the fact that the melodic minor has different pitch sequences depending on whether the pitch is rising or falling. A number of additional heuristics should be employed. For example, although there are three possibly keys for the song Mary had a Little Lamb, the tonic of one of those keys is never played, and hence shouldn't be considered.
Most modulations move to a key which shares many of the same notes from the previous key.
Using this heuristic we would expect a more rapid convergence to a new key after a reset. The work should be extended to use harmony information from accompanying chords. The names of the tonics should be changed so that the name of a tonic that could be sharp or flat is unambiguously named as the tonic with the smaller number of accidentals in its key signature. References H.C. Loguet-Higgons, Perception of Melodies, in Natural Computation, ed. The Complete Table of Interval Roles in the Major Scale.