Refactoring load image functionality