simplify code
fix possible infinite refresh bug