Finished version of key retrieval