Create Output function

- Build a function to write result into a csv file
- Bug fixing
- Code clean up
Revert "Create Output function"

This reverts commit e21efccbdc74177c2143c25efff5a8dc9baf56a7.