Fixing some logic issues with writing data files.

Just moving some places where the data array is declared
and how the file is written out.
Merge pull request #8 from doowb/master

Fixing some logic issues with writing data files.