REFACTOR made statistics.py a useful library function