Refactored download task into reusable function.