Fix KeyError catching