Fixed potential infinite loop during startup and stop of service