Correct undefined element problem

fixed with simple conditionl statement