rewrite upload and submit logic