Added expand nodes and undefined checking