Refactoring file upload