Index out of bounds error - check thread