Fixed some bugs with cache