Performance

Improving performance of switching a theme from ~1700ms to ~110ms. See commit message on bf94760 to see how!

Also adding some tests that were a byproduct of some performance changes I decided not to stick with, but useful to have anyway!