now the download data functionality works and I cleaned up the code a bit