This a minor nit pick around code duplication, but perhaps we can use a private method that takes a Set and key, then this does the check, warn, and add. We could probably use that in four places