cleanup and rewrote the refreshing mechanism to always use one javascript thread