as suggested by @pqwy, use index_from and not be quadratic in space