add support for freeing threads