averge function bug fix