Fixed file upload and error checking