refactored img upload