NOTE: change to_csv function to use DictWriter