Refactored ContainsKey calls to ensure indexing will not be attemped with key that DNE.