added key judgment logic