This is a little more complicated than you might expect, there's several different things that have to work right: