It took me a while to understand why some things are implemented the way they are, so hopefully it will help future readers.