  In the framework of nuclear magnetic resonance, we consider the general
problem of the coherent control of a spin coupled to a bath by means of
composite or continuous pulses of duration $\tau_\mathrm{p}$. We show explicity
that it is possible to design the pulse in order to achieve a decoupling of the
spin from the bath up to the third order in $\tau_\mathrm{p}$. The evolution of
the system is separated in the evolution of the spin under the action of the
pulse and of the bath times correction terms. We derive the correction terms
for a general time dependent axis of rotation and for a general coupling
between the spin and the environment. The resulting corrections can be made
vanish by an appropriate design of the pulse. For $\pi$ and $\pi/2$ pulses, we
demonstrate explicitly that pulses exist which annihilate the first and the
second order corrections even if the bath is fully quantum mechanical, i.e., it
displays internal dynamics. Such pulses will also be useful for quantum
information processing.
