Fixed undefined checking