Return correct ID for each term_id

Fixes #3