Refactored thread stopping methods.