updated download function