Adding check for valid images