Refactor of the music function