Refactored code into functions, to skip downloading if data already downloaded