Converted the output to csv form as specified in the CSV file and performed a lot of code refactoring operations to make the code easier to understand and maintain