fixing thread cleanup