Tweaked csv export to allow custom queries.