refactoring image upload. improvements