changed undefined check to null check