massive simplification of takeAvg.pl