You only need one loop here, in fact you don't need to keep alreadyUploaded and alreadyDownloaded separate.