changed API code to use thread data pointer instead of variables