replaced switch with ifelse