Miscellaneous tweaks and optimizations