added polling to check for DOM paint completion