Refactoring load images functionality