refactoring of the g-test functionality in simple stats