fixed some possible exceptions