Refactored to_csv code. Now in it's own module so it doesn't pollute Array namespace. Also fixes issue 223.