Fix handling of mask and tweak mask test