 // ... your helper functions
 
 // ... more ...
-bool nearestIntersection(in Ray ray, float t)
-{
-    float dist = INFINITE;
+bool nearestIntersection(in Ray ray, out float t)
+{
+    t = INFINITY;
     float t0;
     float t1;
 
 	for(int i = 0; i < SIZE; ++i)
 	{
-        if(intersects(blobs[i], ray, t0, t1) && t0 < dist)
-        {
-            dist = t0;
-        }
-	}
-
-    t = dist;
-	return dist < INFINITY;
-}
-
-bool farthestIntersection()
-{
-    float dist = 0;
+        if(intersect(blobs[i], ray, t0, t1) && t0 < t)
+        {
+            t = t0;
+        }
+	}
+
+	return (t < INFINITY);
+}
+
+bool farthestIntersection(in Ray ray, out float t)
+{
+    t = 0;
     float t0;
     float t1;
 
 	for(int i = 0; i < SIZE; ++i)
 	{
-        if(intersects(blobs[i], ray, t0, t1) && t0 > dist)
-        {
-            dist = t0;
-        }
-	}
-
-    t = dist;
-	return dist > INFINITY;
-}
-
+        if(intersect(blobs[i], ray, t0, t1) && t0 > t)
+        {
+            t = t0;
+        }
+	}
+
+	return (t > 0);
+}
+
+bool getDistance(in vec3 position, in int sphere, out float t)
+{
+    t = sqrt(    pow(blobs[sphere].position.x - position.x, 2) +
+                    pow(blobs[sphere].position.y - position.y, 2) +
+                    pow(blobs[sphere].position.z - position.z, 2)) - blobs[sphere].radius;
+    return true;
+}
+
+bool nearestDistance(in vec3 position, out float t)
+{
+    t = INFINITY;
+    float t0;
+
+	for(int i = 0; i < SIZE; ++i)
+	{
+        if(getDistance(position, i, t0) && t0 < t)
+        {
+            t = t0;
+        }
+	}
+
+	return (t < INFINITY);
+}
+
+bool hitSphere(in vec3 position, out int sphere)
+{
+    float t;
+
+    for(int i = 0; i < SIZE; ++i)
+	{
+        if(getDistance(position, i, t) && (t <= 0))
+        {
+            sphere = i;
+            return true;
+        }
+	}
+    return false;
+}
 
 bool trace(in Ray ray, out vec3 normal, out Material material, out float t)
 {

	// your shader should terminate!

	// return true if iso surface was hit, fals if not


	return false;
}

// Task_5_3 - ToDo End

	// find nearest and farthest intersection for all metaballs
	// hint: use for loop, INFINITE, SIZE, intersect, min and max...



	float tmin;
	float tmax;

	if(!farthestIntersection(ray, tmax) || !nearestIntersection(ray, tmin))
    {
        return false;
    }

	// implement raymarching within your tmin and tmax
	// hint: e.g., use while loop, THRESHOLD, and implment yourself
