Fixes bug when there are multiple masks in a group