Add Download functionality, fix some bugs