Corrected choose_mask function