fixing a few KeyError bugs