Fixed bug in rhythm calculation