Fix for flicker on initial click, various performance improvements

Simple caching of values, and some improvements to element creation. 
Sometimes, when clicking on a thumbnail, the thumbnail would flicker before the animation begins, should be resolved now.