refactoring and delete image func