fix phase calculation