Extended functionality and code cleanup

I extended the functionality to return the CSV data directly, instead of only save it to a local file (see new example) and also cleaned up the code a bit.