check key exists before using it

if you don't check a key exists before using it, it'll cause a warning to happen, so I think it's better to do this, maybe it should throw an exception instead of returning NULL ?

Signed-off-by: Christopher Thomas <chris.thomas@antimatter-studios.com>