Fixes and optimisations.