Clean up.
Add button export csv in main page. Generalize csv function. Clean up.