added memory control