Refactor indexes out of distance metrics.