the above sounds about right to be honest.

Mucus is there to protect shit from getting onto very fargile membranes and linings of your lungs.

Once the shit is trapped in the mucus your body either digests it or ejects it. The more you expand you lungs with work done the more your body will want to protect itself as the more delicate and lesser used areas of the lungs are used.

Obvioisly Asthma or any respiratory disorder will increase phlegme as will eating dairy products.