CSV output improved

Bug fix and csv output improvments