Fix export csv, improvements query