memory accounting work and fixes