improve the upload function