completely rearrange code to avoid blocking UI or WebCore