public static Pair findClosestPairHelper(XYPoint pointsByX[], XYPoint pointsByY[], int nPoints, Pair closest)	{
		if (nPoints == 1){ // If nPoints return Pair with coordinates null (dist = INF)
			return new Pair(null,null); 
		}
		if (nPoints == 2){// If nPoints, compare the distance between the two, with the smallest distance calculated so far
			return closest.returnMin(new Pair(pointsByX[0],pointsByX[1]));
		}

		int mid = (int) (Math.floor((nPoints/2)));

		int rightlength =  nPoints - (mid);
		int leftlength = mid;
		XYPoint[] XL = new XYPoint[leftlength];
		XYPoint[] XR = new XYPoint[rightlength];
		System.arraycopy(pointsByX, 0, XL, 0, leftlength);
		System.arraycopy(pointsByX, leftlength , XR, 0, rightlength);

		XYPoint[] YL = new XYPoint[leftlength];
		XYPoint[] YR = new XYPoint[rightlength];
		int j = 0;
		int k = 0;
		for (int i = 0; i < nPoints; i++)
		{ //Use is left of to calculate which points are 
			if (pointsByY[i].isLeftOf(pointsByX[mid])){ 
				YL[j] = pointsByY[i];
				j++;
			}
			else{
				YR[k] = pointsByY[i];
				k++;
			}
		}

		Pair ClostestLeftPair = findClosestPairHelper(XL,YL,leftlength,closest);
		Pair ClostestRightPair = findClosestPairHelper(XR,YR,rightlength,closest);

		return combine(pointsByY, pointsByX[mid], ClostestLeftPair.returnMin(ClostestRightPair));
	}