Minor fixes and optimisations.