make Gram matrix version better