finished getLagIndex method