Added more error checking to flush-caches