I see that this does the job, but I don't agree the squaredNorm is mathematically correct.