Fixed some bugs, added some debugging output to cache.c