Fixed code and output csv data