cleaned up code to better match existing download function