improved file upload code