Fix direction calculation.