Performance tweaks and fixes