Fixed calculation of frequency to run