add invalidation and fix bugs