refactor stop code slightly