fix bugs that cache can be corrupted