Fixed race condition issue with images loading