fix the leak in allocation where hashtable has more items than intended.
refactor all stats in one place and remove duplicate helper methods.