Changing undefined to second if