Fix some mask calculations