Added template masking stage