mask updating: avoid nans