Changed melody algorithm