Added precomputation of endInner.