modified getMask function