Added generic stats collection
Changed standard math librarry to cmath