Modified code for averaging the timing