Simplify segment lookup loop.
Fix assertion.