Fix in-place memory bug while iterating through terms, add undocumented terms_count field, testing it out