Move masking functions to core