implemented avg function