Modified the export function according to the feedbacks from GitHub - pullrequest #376