Export to csv and several fixes