Beefed up tests and added valid key check