refactored to use numpy nanmean rather than the scipy version