refactored refresh logic