Added error handling and CSV printout
Added main test case in test.rb