some fixes that prevent null pointer conditions