cleanups and more optimisations