download function and main function