Refactored CSV export functionality to sit in it's own class.

Relates to #2802 #2431#3408