Fix calculating index method