fix keyerror exception