clean up code and change from text to csv