Fixed some race conditions when loading images