enhance defined/undefined logic