Remove if (type != NULL), which due to prior program logic cannot be false.