Add a guard code to manage image loading