added CSV writing