change the mode function from average.py