Fix weird bugs that created infinite loop on downloads' end