Fixed key creation logic in invalidate function