Minor fixes and optimisations.
Fixed permissions and other fixes