improved auto stop function