Fix bugs in masking
Added tests for masking