-Added support that a pregenerated mask can be provided, which overrides the internally generated mask