cleaning up + more optimisations and memory management imporvements