Many memory optimisations, mostly array copies