Added main movement calculation function.