fix some possible exceptions