fix ifelse function