refactoring fileupload and other bug fatch