minor refactoring; added comment
added TODO
significantly generified output
able to write csv output to file