Factorize (and fix) gaussian weight computation