csv writing and some query/storage changes