Download function, bug: only works after second click