moved index to its own method