properly handling keyerror