Refactoring: moving index helper function tothe basic library.