added documentation and also changes the code to output .csv and .txt file