adding undefined check for depth