Added main and write_csv functions, may need to redesign data extraction. Getting very sloppy.