Added some form of key-checking

(This can probably be made far, far better)
Also fixed up a timing issue