Fixed avg to handle NaN cases.
#MBL-10146 Fixed