use isnan, and 0 instead of zero