moved csv creation into method
added nil check for field headers on csv