add average algorithm