created a function to hold csv creation code