adding undefined check