refactored the algorithm into the model and created the download functionality