Fix bug in creating mask and another one in dividing the data by the scale.