corrected refresh function