added functionality to output dataset for further analysis
added a number of comments to code