changed switch to ifelse