Loop over the caches instead of writing a loop for each cache
Remove incorrect shortcut out of ancestor(int, int) method