Cleaned up, and now outputs to csv file.