added thread cleanup handlers