fixing aggrigation and matrix overflow