countPastDataStats function added, fix some bugs