The coherent control of small quantum system is considered. For a two-level system coupled to an arbitrary bath we consider a pulse of finite duration. We derive the leading and the next-leading order corrections to the evolution operator due to the non-commutation of the pulse and the bath Hamiltonian. The conditions are computed that make the leading corrections vanish. The pulse shapes optimized in this way are given for π and 2π pulses.