Refactoring code to include uploading of files