add func avg, learn range/cap/func definition