Using switch in bound() leads to bugs and inefficiencies, since both alternatives are always evaluated, even if one of them is invalid. Use ifelse instead