Changed arbitrary replacement for NaN to 0