refactored image upload