improved parsing of CSV and some cleanups