Adds csv writing, config file and general bugfixes.