fixed a bug in replace_by_children