Premature thread termination fixed