A bunch of performance tweaks (mainly caching)