Refactoring the image upload