Check the key to prevent warnings

Actually this code is throwing some warnings due the key is not present in all the cases. My concern is to verify first if the key is present before to check the value.