Performance tweaks

More performance tweaks recommended by agentzh