Small fixes and optimisations