First working version, added csv option