Changed key checking

I fiddled around with the key checking mechanism.
Not sure if it still works though. I didn't check.