refactoring and simplying calculation upto gaussian