Fixed bugs raised by new cache clearing routine