better avg function (works now?)