move d/l func out of main code