Cachematrix modified as a part of assignment2