fixed a bug where positions were being computed N times per iteration, instead of once.