I can absolutely imagine this done in a bunch of different ways, and some of them would look like the scribblings of a child, and another approach could be really elegant. One approach may be built to extend, while the other just gets the job done. One approach may trade speed for readability, or vice versa.