More progress done on the stats function, relates to issue #62