moved creating and freeing API thread data to separate functions