Fix null pointer references