Implemented download in ranges. Major refactor of the code into smaller chunks