fixed heading calculation and dot product algorithm