added average function