change to detect source function at first to reduce calculation amount
change to allocate and free tale_defs at the minimum number of times