Re-wrote average function using lambda