Refactored addImagesToContainer to use inner function.