refactor code for generating CSV
add command-line argument parsing