fix some possible null ref exceptions