Refactor upload