Hopefully made this easier to understand at a glance and more efficient. This should squash when merged