Code for performing statistics