Modify animate() function to limit the refresh rate.