added indexes array to sample function