cleaner code for mask mode