auto detect start and stop