fix self-reference algorithm to use more intelligent choices