Check for dictionary items before accessing them

Change-Id: I28272b8fff78805f4f5cd0d0a32d235298cb03a2