fixing KeyError issues