added utility function to main script; fixed export bug