Improved logging. Now writes a CSV