hard to understand with text, try with a video
From experiences , twisting comes when the bones angles are approching the line to ik target
Also for mecanical parts , i would highly recommand using only dummies and no bones at all
other theory, in motion panel make sure you are in euler rotation aswell translate x,y,z