Some fixes in file upload logic