refactor type_function