add upload function and refactor