changes to fix the KeyError