memory management, works so far
memory management final