Several optimisations and fixes...