clean up cache checks and fix possible race