Fix race condition with image loading.