Merge changes from develop branch - general code improvements and optimisations