Run test three times and calculate average. Slight cleanup of variables