Added own implementation of cache matrix