Refactor uploading