Fixed bugs in CSV parsing/writing