change factorial to higher-order func