Fix a possible exception about keys not being within the range of the Dictionary