Moved thread stop check to innermost first loop