Refactored indexterm handling

* refined indexterm logic
* added tests