fixed a bug in the key check code