Fix to preloadImages helper function