Added proper calculation of stats

fixes #215
fixes #214