close and refresh logic