added memory management