optimizing multiple mask switching