improved plugin stop waiting code