refactor the data upload code.