     // TODO add reflection and refraction
     if (rand.NextFloat01() < emission_reflection.w) {
         // ray is reflected
-        dir = dir - norm * 2 * dot(norm, dir);
+        dir = dir - rayNorm * 2.0f * dot(rayNorm, dir);
     } else if (rand.NextFloat01() < color_refractions[matID].w){
-        float3 reflect = dir - norm * 2.0f * dot(norm, dir);
+        float3 reflect = dir - rayNorm * 2.0f * dot(rayNorm, dir);
         
         // Pure magic 'borrowed' from smallpt
         float nc = 1.0f, nt = 1.5f;
         float nnt = into ? nc/nt : nt/nc;
-        float ddn = dot(dir, norm);
+        float ddn = dot(dir, rayNorm);
         float cos2t = 1.0f - nnt * nnt * (1.0f - ddn * ddn);
         
         if (cos2t < 0.0f) {
             dir = reflect;
         } else {
-            float3 tDir = normalize(dir * nnt - norm * (ddn*nnt+sqrt(cos2t)));
-            float a=nt-nc, b=nt+nc, R0=a*a/(b*b), c = 1-(into?-ddn : dot(tDir, norm)); // TODO This norm is actually flipped. Does it matter?
+            float3 tDir = normalize(dir * nnt - rayNorm * (ddn*nnt+sqrt(cos2t)));
+            float a=nt-nc, b=nt+nc, R0=a*a/(b*b), c = 1-(into?-ddn : dot(tDir, sphereNorm));
             float Re=R0+(1-R0)*c*c*c*c*c;
             float P = 0.25f + 0.5f * Re; 
             // float Tr = 1.0f - Re;

    const Sphere sphere = spheres[hitID];

    const float3 hitPos = t * dir + rayOrigin; // we could store hitPos in the rays origin, since we should already know it from the intersection test.
    float3 norm = normalize(hitPos - sphere.center);
    const bool into = dot(norm, dir) > 0.0f;
    norm = into ? norm * -1.0f : norm;
    
    Random rand = Random::Create1D(seed);
    
    float colorContribution = 0.0f;

        const float r2 = rand.NextFloat01();
        const float r2s = sqrtf(r2);
        // Tangent space ?
        const float3 w = rayNorm;
        const float3 u = normalize(fabsf(w.x) > 0.1f ? 
                                   make_float3(0,1,0) : 
                                   cross(make_float3(1,0,0), w));
        const float3 v = cross(w, u);
        dir = normalize(u * cos(r1) * r2s + v * sin(r1) * r2s + w * sqrtf(1.0f-r2));
