Fixed get_avg_func bug. get_avg_func is still unoptimized though