Refactor, Fix subthread not exiting