Added tests.  Changed CSV functionality to be more secure against bad input.