Moved csv output to function. Build sets.