add codes for gathering statistics