         if (x < labels.x && y < labels.y && z < labels.z) {
 
             int label;
-            int foreground;
-            long long buffer;
+            unsigned char foreground;
+            unsigned long long buffer;
 
             if (x + 1 < labels.x) {
-                buffer = *reinterpret_cast<long long *>(labels.data + labels_index);
+                buffer = *reinterpret_cast<unsigned long long *>(labels.data + labels_index);
                 label = (buffer & (0xFFFFFFFF)) + 1;
                 foreground = (buffer >> 32) & 0xFFFFFFFF;
             }

            }

            if (x + 1 < labels.x) {
                *reinterpret_cast<long long *>(labels.data + labels_index) = (static_cast<long long>(((foreground << 30) >> 31) & label) << 32) | (((foreground << 31) >> 31) & label);

                if (y + 1 < labels.y) {
                    *reinterpret_cast<long long *>(labels.data + labels_index + labels.stepy / labels.elem_size) = (static_cast<long long>(((foreground << 28) >> 31) & label) << 32) | (((foreground << 29) >> 31) & label);
                }

                if (z + 1 < labels.z) {
                    *reinterpret_cast<long long *>(labels.data + labels_index + labels.stepz / labels.elem_size) = (static_cast<long long>(((foreground << 26) >> 31) & label) << 32) | (((foreground << 27) >> 31) & label);
                    
                    if (y + 1 < labels.y) {
                        *reinterpret_cast<long long *>(labels.data + labels_index + labels.stepz / labels.elem_size + (labels.stepy / labels.elem_size)) = (static_cast<long long>(((foreground << 24) >> 31) & label) << 32) | (((foreground << 25) >> 31) & label);
                    }
                    
                }
            }
            else {
                labels[labels_index] = ((foreground << 31) >> 31) & label;

                if (y + 1 < labels.y) {
                    labels[labels_index + (labels.stepy / labels.elem_size)] = ((foreground << 29) >> 31) & label;
                }

                if (z + 1 < labels.z) {

                    labels[labels_index + labels.stepz / labels.elem_size] = ((foreground << 27) >> 31) & label;

                    if (y + 1 < labels.y) {
                        labels[labels_index + labels.stepz / labels.elem_size + (labels.stepy / labels.elem_size)] = ((foreground << 25) >> 31) & label;
                    }

                }


                if ((HasBit(P, 20) && plane_data[-1]) || (HasBit(P, 24) && plane_data[img.stepy - 1]) || (HasBit(P, 36) && plane_data[img.stepz - 1]) || (HasBit(P, 40) && plane_data[img.stepz + img.stepy - 1])) {
                    Union(labels.data, labels_index, labels_index - 2);
                }
            }

        }
    }

