improve keyerror fix