fixed bug that caused masking to be done in reverse.