Improved restart logic.