Minor fixes and optimisations