load_images.js: code refactoring; use the flag more