Fixed boolean ifelse to vectorize properly