Refactor S3 uploading