extract logic reuse in index