Merged code from zhum/hopcsv