Twist bones get flipped at certain angles

Hello I have this control rig with simple ik on the legs and I added twist to the twist bones. The 1 issue is that the twist bones flip when they reach a certain angle.