Some tweaks for efficiency, and fixes.