Spline mesh twists randomly

So I’m working some tree generation that uses some basic trig to randomly generate the points to create a spline. While I have basically everything working, I am now trying to get rid of the kinks and twists the spline. Since it is made in the construction script I can’t change tangents manually, so I need some sort of math way to stop from getting these ugly knots.