Correct computation of all variants.
Removed some optimizations which caused illegal results.
Added optimization to OpenCL kernels.