Add some fixes and optimisations