added key check and replaced duplicate answer