more efficient fix for the mask problem