Add stop functionality to thread