Assuming that masks never contains arbitrary symbols, in theory you should be able to just run over the whole masks Map and canonicalize the key and values w/o checking containsKey