refactored code to handle different refresh rates