command end & improved restart logic