slight modification of stopping code