Fix bug in refresh thread