working on average func