Added csv support and updated the error handling.