start refactoring the upload function