Fix calculation error and did code condense

Bundle all the higher moments calculation into one function