optimize function serialization, fix circularReference index issue