Fully implemented the export algorithm