Had duplicated line outside ifelse statement