optimized the refresh loop