Replaced remaining ifelse with a switch. This not only will fix the build but results in a ~78% speed up over the initial approach!