change the check to try except as a failure returns a KeyError