More reorganising and a few more optimisations