complete download functionally. refactoring code