The functions was written in a way that would possibly resize the mask twice, which is not necessary.