Fixed bug in calculating displacement in toroidal wrapping mode