changing some undefined check to use angular function