added caching code to store column and row sums of count matrices