Fix null pointer errors