build main function