Updated version with CSV writer
Updated tests