hacky optimization of dot product