updated tempIndex = tempIndex + 1 to tempIndex++ for consistency