fixed memory leaks, track memory sizes