Tweak the preloadImages function, add callback when all images are loaded