Added a CSV export feature and cleaned up sorting.