clean the code and correct some errors regarding the file upload