use more efficient lowest common ancestor algorithm