Copied some voodoo type magic for dot products