more or less working avg2.js