Minor optimisations and fixes.