looks like you could extract lines 42-49 which are identical to 28-36 (minus the unused exportURL variable) into a helper function.