overlay algorithm more robust.