refactor uploading of files