rearranging and collecting terms



I hope this is not too much a trivial question, I'm a newbie to Maxima. I'd 
like to rearrange expressions like this

(3*cos(d1)^3-3*cos(d2)^3)*x

or this

(3*a*b1-3*a*b2)*x

into a simpler form with collected terms;

3*(cos(d1)^3-cos(d2)^3)*x

3*a*(b1-b2)*x


Is there a solution that works in BOTH cases ?

Factor  or  facsum  work for the 2nd expression but lead to unwanted 
trigonometric expansion in the 1st expression.

It seemed to me a very simple rearrangment to do but i could not find a 
solution after a long search.

Thank you very much for your help.

Mario M.