fixed js race conditions