Various performance tweaks and style cleanup