Robust key fetching

Fixes #31
Merge pull request #33 from Bouke/patch-2

Robust key fetching