Not sure how many times through the while loop we go, but perhaps the setting evaluation could be done at the top to save the map lookup over and over?

If only  a few, no problem (particularly if it's planned to remove it later).