code and performance optimisations