Version 2 with refined comments and logic

This version has lesser, readable comments and changed the export
feature of the file to cdv