undefined check added